import { ResponsePage } from '@/domain/entity/ResponsePage';
import { Role } from '@/domain/entity/Role';
import { RoleListQuery } from '@/domain/query/RoleListQuery';
import axios from '../config/AxiosConfig';
import { Result } from '../domain/entity/Result';

const moduleUrl = "/system/system-role";

const getListUrl = moduleUrl + "/getList";
const getListPageUrl = moduleUrl + "/getListPage";
const getDetailUrl = moduleUrl + "/getDetail";
const updateRoleUrl = moduleUrl + "/update";
const createRoleUrl = moduleUrl + "/create";
const removeRoleUrl = moduleUrl + "/delete";
const updateDisabledUrl = moduleUrl + "/updateDisabled";

export const getList = function () {
    return axios.get<Result<Array<Role>>>(getListUrl);
}

export const getListPage = function (roleListQuery: RoleListQuery) {
    return axios.get<Result<ResponsePage<Role>>>(getListPageUrl, {
        params: roleListQuery,
    });
}

export const getDetail = function (roleId: string) {
    return axios.get<Result<Role>>(getDetailUrl + "/" + roleId);
}

export const update = function (role: Role) {
    return axios.put<Result<Role>>(updateRoleUrl, role);
}

export const create = function (role: Role) {
    return axios.post<Result<Role>>(createRoleUrl, role);
}

export const remove = function (roleId: string) {
    return axios.delete<Result<string>>(removeRoleUrl + "/" + roleId);
}

export const updateDisabled = (roleId: string) => {
    return axios.put<Result<string>>(updateDisabledUrl + "/" + roleId);
}